Projet_Covid¶

In [21]:
import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt
import folium
from folium import plugins
import numpy as np 

url = "https://static.data.gouv.fr/resources/synthese-des-indicateurs-de-suivi-de-lepidemie-covid-19/20230630-155909/table-indicateurs-open-data-dep-2023-06-30-17h59.csv"
df = pd.read_csv(url, sep=",")
#df.head()



#print("\n Before transformations:\n")
#print(df.dtypes)

if(df.date.dtype == 'object'):
    transfo_date = lambda x : dt.datetime.strptime(x, "%Y-%m-%d")
    df.date = df['date'].apply(transfo_date)

if(df.lib_dep.dtype == 'object'):
    df.lib_dep = df.lib_dep.astype('string')
if(df.lib_reg.dtype == 'object'):
    df.lib_reg = df.lib_reg.astype('string')

#print("\n After transformations:\n")
#print(df.dtypes)

geo_url = "https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements.geojson" # GeoJSON URL 
C:\Users\zouad\AppData\Local\Temp\ipykernel_20724\2069844688.py:9: DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.
  df = pd.read_csv(url, sep=",")

KPI (Infos générale)¶

Bilan Humain Total¶

Analyse du nombre de décès total en france

In [22]:
total_death = df.dchosp.sum()
print(f"\n Nombre total de décès en france suite au COVID-19 : {total_death}\n")
 Nombre total de décès en france suite au COVID-19 : 103245818

Pic d'hospitalisation¶

Record du nombre d'hospitalisation dû au COVID-19

In [23]:
max_infected = df.hosp.max()
date_max_infected = df.loc[df.hosp.idxmax(), 'date'].date()
print(f"\n À la date du {date_max_infected}, il y a eu le plus d'hospitalisation avec un nombre de {max_infected} cas.\n")
 À la date du 2020-04-14, il y a eu le plus d'hospitalisation avec un nombre de 3281 cas.

Dépistage : taux de positivité¶

Taux moyen d'un dépistage positive sur la période du COVID

In [24]:
positive_avg = df.pos.mean()

print(f"\n Le nombre moyen de cas positifs par jour en France est de {positive_avg:.2f} cas.\n")
 Le nombre moyen de cas positifs par jour en France est de 335.42 cas.

Graphiques des critères¶

Évolution des cas COVID-19 en France¶

In [25]:
import matplotlib.pyplot as plt

dates = df['date'].unique()
len(dates)
df['day_of_week'] = df['date'].dt.day_name()
day_mapping = {
    'Monday': 'Lundi',
    'Tuesday': 'Mardi',
    'Wednesday': 'Mercredi',
    'Thursday': 'Jeudi',
    'Friday': 'Vendredi',
    'Saturday': 'Samedi',
    'Sunday': 'Dimanche'
}
df['day_of_week'] = df['day_of_week'].map(day_mapping)

Graphe de la saturation¶

In [26]:
# Adapter les données pour lisibilité
hospitalisations = df.groupby('date')['hosp'].apply(lambda x : x.sum()).values

plt.figure(figsize=(12, 6))
plt.title("Saturation des hôpitaux pendant le COVID-19 en France")
plt.xlabel("Date")
plt.ylabel("Nombre d'hospitalisations")
plt.plot(dates, hospitalisations, label='Hospitalisations', color='blue')
plt.show()
No description has been provided for this image

Répartition journalière¶

Analyse des cas par rapport au jour de la semaine

In [27]:
# Répartition par jour de la semaine des nouvelles hospitalisations
from hmac import new

new_hosp_by_day = df.groupby('day_of_week')['incid_hosp'].mean()
new_infect_by_day = df.groupby('day_of_week')['pos'].mean()
days_order = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
new_hosp_by_day = new_hosp_by_day.reindex(days_order)
new_infect_by_day = new_infect_by_day.reindex(days_order)
plt.figure(figsize=(10, 5))
plt.title("Répartition moyenne des nouvelles hospitalisations et des cas positifs par jour de la semaine")
plt.xlabel("Jour de la semaine")
plt.ylabel("Nouvelles hospitalisations moyennes")
new_hosp_by_day.plot(kind='bar', color='red')
new_infect_by_day.plot(kind='bar', color='green', alpha=0.3)
plt.legend(["Nouvelles hospitalisations de la journée", "Nouveaux cas positifs de la journée"])
plt.show()
No description has been provided for this image

Carte de distribution¶

In [28]:
## Carte Impact Départemental
# URL du découpage géographique des départements (Open Source)

# Création de la carte centrée sur la France
m = folium.Map(location=[46.5, 2], zoom_start=6, tiles="CartoDB positron")

# --- 3. Création de la couche Choroplèthe ---

variable_a_afficher = input("Entrez la variable à afficher dchosp : décès cumulés à l'hôpital, TO : taux d'occupation, pos_7j : cas positifs, hosp : hospitalisations, rea : réanimations\n")
titre_legende = "Impact COVID-19 - " + variable_a_afficher

folium.Choropleth(
    geo_data=geo_url,
    name="Choropleth",
    data=df,
    columns=['dep', variable_a_afficher],
    key_on='feature.properties.code',
    fill_color='YlOrRd',                 
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name=titre_legende,
    nan_fill_color="white",
    bins=8                              
).add_to(m)



# --- 4. Affichage ---
folium.LayerControl().add_to(m)



m.save("carte_distribution_covid.html")
m
Out[28]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Carte de la Tension Maximale¶

In [29]:
# 1. Calcul du Maximum par département
df_max_tension = df.groupby('dep')[['TO']].max().reset_index()

# 2. Configuration de la carte
m = folium.Map(location=[46.5, 2], zoom_start=6, tiles="CartoDB positron")

# 3. Création des seuils de couleur
# < 0.6 (60%) : Situation calme (Vert/Jaune)
# 1.0 (100%)  : Saturation (Orange)
# > 1.0       : Débordement / Transferts nécessaires (Rouge)
my_bins = [0, 0.4, 0.6, 0.8, 1.0, 1.5, 3.0, df_max_tension['TO'].max()]

folium.Choropleth(
    geo_data=geo_url,
    name="Tension Maximale",
    data=df_max_tension,
    columns=['dep', 'TO'],
    key_on='feature.properties.code',
    fill_color='YlOrRd',
    fill_opacity=0.8,
    line_opacity=0.2,
    legend_name="Tension Hospitalière Maximale atteinte (Ratio Lits Réa)",
    nan_fill_color="white",
    bins=my_bins
).add_to(m)

# 4. Affichage
folium.LayerControl().add_to(m)

m.save("carte_tension_maximale.html")
m
Out[29]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Carte de Comparaison Temporelle¶

In [30]:
# 1. Sélection des données 
date_vague1 = '2020-04-15' 
date_vague2 = '2022-01-25'

# On nettoie les données
df_1 = df[df['date'] == date_vague1].copy().dropna(subset=['hosp'])
df_2 = df[df['date'] == date_vague2].copy().dropna(subset=['hosp'])


global_max = max(df_1['hosp'].max(), df_2['hosp'].max())
# 2. Calcul de l'échelle commune
common_bins = list(np.linspace(0, global_max, num=7))


# 3. Initialisation de la DualMap
m = plugins.DualMap(location=[46.5, 2], zoom_start=5, layout='horizontal')

# 4. Ajout de la carte de GAUCHE (Vague 1)
folium.Choropleth(
    geo_data=geo_url,
    data=df_1,
    columns=['dep', 'hosp'],
    key_on='feature.properties.code',
    fill_color='Reds',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name=f"Hospitalisations (1ère Vague)",
    bins=common_bins,
    name="Vague 1"
).add_to(m.m1)

# 5. Ajout de la carte de DROITE (Omicron)
folium.Choropleth(
    geo_data=geo_url,
    data=df_2,
    columns=['dep', 'hosp'],
    key_on='feature.properties.code',
    fill_color='Reds',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name=f"Hospitalisations (Vague Omicron)",
    bins=common_bins,
    name="Vague Omicron"
).add_to(m.m2)

# 6. Affichage
folium.LayerControl(collapsed=False).add_to(m)

m.save("carte_comparatif_hospitalisations.html")
m
Out[30]:
Make this Notebook Trusted to load map: File -> Trust Notebook